//
//  ECMineSafeBottomStyleCell.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/15.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECMineSafeBottomStyleCell.h"
#import "CYBlock.h"

@interface ECMineSafeBottomStyleCell()

@property (nonatomic, strong) UIImageView *typeImage;
@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *styleLab;
@property (nonatomic, strong) ECUButton *doBtn;

@end

@implementation ECMineSafeBottomStyleCell

+(ECMineSafeBottomStyleCell *)tableViewCellWithTableView:(UITableView *)tableView{
    static NSString* identifier=@"ECMineSafeBottomStyleCell";
    ECMineSafeBottomStyleCell* cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell=[[ECMineSafeBottomStyleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = 0;
        [cell setCellUI];
    }
    return cell;
}

-(void)setCellUI{
    self.typeImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.typeImage];
    
    self.typeLab = [[UILabel alloc]init];
    [self.contentView addSubview:self.typeLab];
    self.typeLab.font = [UIFont systemFontOfSize:15];
    
    self.styleLab = [[UILabel alloc]init];
    [self.contentView addSubview:self.styleLab];
    self.styleLab.font = [UIFont systemFontOfSize:13];
    self.styleLab.textColor = [UIColor colorWithHexString:@"#b3b3b3"];
    
    self.doBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.doBtn];
    self.doBtn.layer.cornerRadius = 3.f;
    self.doBtn.layer.masksToBounds = YES;
    self.doBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.doBtn addTarget:self action:@selector(doBtn_click:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *lineView = [[UIView alloc]init];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#F1F1F1"];
    
    WeakSelf(weakSelf);
    [self.typeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).offset(kProportion_Width(45));
        make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        make.width.and.height.equalTo(@(kProportion_Width(120)));
    }];
    
    [self.typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeImage.mas_right).offset(10);
        make.top.equalTo(self.typeImage.mas_top);
        make.height.equalTo(self.typeImage.mas_height).multipliedBy(0.5);
        make.width.equalTo(@60);
    }];
    
    [self.styleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeLab.mas_left);
        make.height.equalTo(self.typeLab.mas_height);
        make.top.equalTo(self.typeLab.mas_bottom);
        make.width.equalTo(@60);
    }];
    
    [self.doBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mas_right).offset(-kProportion_Width(45));
        make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        make.width.equalTo(@(kProportion_Width(230)));
        make.height.equalTo(self.doBtn.mas_width).multipliedBy(90.f/230.f);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.contentView.mas_bottom);
        make.left.equalTo(weakSelf.contentView.mas_left).offset(kProportion_Width(45));
        make.right.equalTo(weakSelf.contentView.mas_right).offset(-kProportion_Width(45));
        make.height.equalTo(@1);
    }];
}

-(void)setContentWithData:(NSArray *)arr andIndex:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [self.typeImage setImage:[UIImage imageNamed:@"Mine_safeQQ"]];
        self.typeLab.text = @"QQ";
        
        self.doBtn.tag = 11;
        
        if ([arr[1] intValue] == 1) {
            [self.doBtn setTitle:@"解绑" forState:0];
            self.styleLab.text = @"已绑定";
            
            self.doBtn.backgroundColor = [UIColor whiteColor];
            self.doBtn.layer.borderWidth = 1.f;
            self.doBtn.layer.borderColor = [UIColor colorWithHexString:@"#dedede"].CGColor;
            [self.doBtn setTitleColor:[UIColor colorWithHexString:@"#aaaaaa"] forState:0];
        }else{
            [self.doBtn setTitle:@"立即绑定" forState:0];
            self.styleLab.text = @"未绑定";
            self.doBtn.layer.borderWidth = 0;
            self.doBtn.backgroundColor = [UIColor colorWithHexString:@"#fc6721"];
            [self.doBtn setTitleColor:[UIColor whiteColor] forState:0];
            
        }
    }else{
        [self.typeImage setImage:[UIImage imageNamed:@"Mine_safeWechat"]];
        self.typeLab.text = @"微信";
        
        self.doBtn.tag = 12;
        
        if ([arr[1] intValue] == 1) {
            [self.doBtn setTitle:@"解绑" forState:0];
            self.styleLab.text = @"已绑定";
            
            self.doBtn.backgroundColor = [UIColor whiteColor];
            self.doBtn.layer.borderWidth = 1.f;
            self.doBtn.layer.borderColor = [UIColor colorWithHexString:@"#dedede"].CGColor;
            [self.doBtn setTitleColor:[UIColor colorWithHexString:@"#aaaaaa"] forState:0];
        }else{
            [self.doBtn setTitle:@"立即绑定" forState:0];
            self.styleLab.text = @"未绑定";
            self.doBtn.layer.borderWidth = 0;
            self.doBtn.backgroundColor = [UIColor colorWithHexString:@"#fc6721"];
            [self.doBtn setTitleColor:[UIColor whiteColor] forState:0];
        }
    }
}

//绑定/解绑 按钮
-(void)doBtn_click:(ECUButton *)btn{
    if (self.block_btn) {
        self.block_btn(btn.tag);
    }
}

@end
